package com.lh.io.bio;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) {

        try {
            //1.创建一个Socket的通信管道，请求与服务端的端口连接
            Socket socket = new Socket("127.0.0.1",8088);
            //2.获取字节输出流
            OutputStream os = socket.getOutputStream();
            //3.把字节流改装成自己需要的流进行数据的发送
            PrintStream ps = new PrintStream(os);
            Scanner scan = new Scanner(System.in);

            while (true){
                System.out.print("请输入内容:");
                String msg = scan.nextLine();
                //退出输入
                if (msg.equalsIgnoreCase("exit")){
                    System.exit(1);
                }
                ps.println(msg);
                ps.flush();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
